﻿package com.dbm.model;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;

public class ReadSqlProp {
	
	
	/**
	 * 更新 prop 文件
	 * @param filepath 文件路劲
	 * @param properValue 值
	 * @param properkey    key
	 * @throws Exception
	 */
    public void readUpdateProperties(String filepath, String properValue,String properkey) throws Exception{
    	Properties prop = new Properties();// 属性集合对象 
		FileInputStream fis = new FileInputStream(filepath);// 属性文件输入流 
		prop.load(fis);// 将属性文件流装载到Properties对象中 
		prop.setProperty(properkey, properValue);
		FileOutputStream fos = new FileOutputStream(filepath);
		prop.store(fos, "Copyright (c) by  Gotop111");
		fos.close();// 关闭流 
		fis.close();// 关闭流 
    }
    
    /**
     * 读取 Prop文件
     * @param filepath
     * @param properkey
     * @return value值
     * @throws Exception
     */
    public String readProperties(String filepath ,String properkey) throws Exception{
    	String lastfilepath = null;
    	Properties prop = new Properties();// 属性集合对象 
		FileInputStream fis = new FileInputStream(filepath);// 属性文件输入流 
		prop.load(fis);
    	lastfilepath = prop.getProperty(properkey);
    	fis.close();// 关闭流 
    	return lastfilepath;
    }
}
